package edu.yctc.manage.utils;

import edu.yctc.manage.dao.CourseDAO;
import edu.yctc.manage.dao.ScoreDAO;
import edu.yctc.manage.dao.SdeptDAO;
import edu.yctc.manage.dao.StudentDAO;
import edu.yctc.manage.entity.CourseDO;
import edu.yctc.manage.entity.ScoreDO;
import edu.yctc.manage.entity.StudentDO;
import edu.yctc.manage.enums.Gender;
import edu.yctc.manage.vo.CourseVO;
import edu.yctc.manage.vo.ScoreVO;
import edu.yctc.manage.vo.StudentVO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

/**
 * @ClassName VOUtil
 * @Description TODO
 * @Author zyj
 * @Date 2021/3/29 22:18
 * @Version 1.0
 **/
@Component
public class VOUtil {

    @Resource
    private StudentDAO studentDAO;

    @Resource
    private SdeptDAO sdeptDAO;

    @Resource
    private CourseDAO courseDAO;

    public StudentVO StudentDO2VO(StudentDO studentDO) {
        StudentVO studentVO = new StudentVO();
        studentVO.setId(studentDO.getId());
        studentVO.setSdeptName(sdeptDAO.selectById(studentDO.getSdeptId()).getName());
        studentVO.setName(studentDO.getName());
        studentVO.setGender(Gender.getGenderValue(studentDO.getGender()));
        return studentVO;
    }

    public List<StudentVO> StudentDOs2VOs(List<StudentDO> studentDOS) {
        List<StudentVO> studentVOS = new LinkedList<>();
        for (StudentDO studentDO : studentDOS
        ) {
            StudentVO studentVO = new StudentVO();
            studentVO.setId(studentDO.getId());
            studentVO.setSdeptName(sdeptDAO.selectById(studentDO.getSdeptId()).getName());
            studentVO.setName(studentDO.getName());
            studentVO.setGender(Gender.getGenderValue(studentDO.getGender()));
            studentVOS.add(studentVO);
        }
        return studentVOS;
    }

    public StudentDO StudentVO2DO(StudentVO studentVO) {
        StudentDO studentDO = new StudentDO();
        studentDO.setName(studentVO.getName());
        studentDO.setSdeptId(sdeptDAO.getSdeptDOByName(studentVO.getSdeptName()).getId());
        studentDO.setGender(Gender.getDBGenderValue(studentVO.getGender()));
        return studentDO;
    }

    public List<CourseVO> CourseDOs2VOs(List<CourseDO> courseDOS) {
        List<CourseVO> courseVOS = new LinkedList<>();
        for (CourseDO courseDO : courseDOS) {
            CourseVO courseVO = new CourseVO();
            courseVO.setId(courseDO.getId());
            courseVO.setName(courseDO.getName());
            courseVO.setSdeptName(sdeptDAO.selectById(courseDO.getSdeptId()).getName());
            courseVOS.add(courseVO);
        }
        return courseVOS;
    }

    public List<ScoreVO> ScoreDOs2VOs(List<ScoreDO> scoreDOS) {
        List<ScoreVO> scoreVOS = new LinkedList<>();
        for (ScoreDO scoreDO : scoreDOS) {
            ScoreVO scoreVO = new ScoreVO();
            scoreVO.setId(scoreDO.getId());
            scoreVO.setScore(scoreDO.getScore());
            scoreVO.setCourseName(courseDAO.selectById(scoreDO.getCourseId()).getName());
            scoreVO.setStudentName(studentDAO.selectById(scoreDO.getStudentId()).getName());
            scoreVO.setSdeptName(sdeptDAO.selectById(courseDAO.selectById(scoreDO.getCourseId()).getSdeptId()).getName());
            scoreVOS.add(scoreVO);
        }
        return scoreVOS;
    }

}
    